// 引入koa-router
const Router = require('koa2-router');
const router = new Router();

const fs = require("fs");

router.post('/',function (ctx) {
    // console.log(ctx.request.file);
  // req.file is the `avatar` file
  // req.body will hold the text fields, if there were any

  //   {
  //     fieldname: 'banner',
  //     originalname: '2.jpg',
  //     encoding: '7bit',
  //     mimetype: 'image/jpeg',
  //     destination: '../../../public/images',
  //     filename: '6270d0083fa9b13a8d32ecf091c9435b',
  //     path: '..\\..\\..\\public\\images\\6270d0083fa9b13a8d32ecf091c9435b',
  //     size: 167082
  //   }
  const oldPath = ctx.request.file.path;
  const newPath = ctx.request.file.destination + "/" + ctx.request.file.originalname;
  //   console.log(oldPath, newPath);
  fs.renameSync(oldPath, newPath);
  ctx.body = 'ok';
});

module.exports = router;


